<?php
require_once("func.php");

#$in = "husk maelk /// husk kat /// husk kat";
#$in = "husk maelk ";
#$tasksep = "///";
#$tasks = explode($tasksep, $in);

#debug($tasks);

#exit();

#debug($_POST);

$tasksep = "///";

if(!empty($_POST['submit']))
{
	if($_POST['submit'] === "submit")
	{
		$tasks = explode($tasksep, $_POST['txt']);

		foreach($tasks AS $task)
		{
			$task = trim($task);

			if(!empty($task))
			{
				$sql = "insert into todos (pid,txt,prio,hours,severity,date_added) values (
						'".$_POST['pid']."',
						'".$task."',
						'".$_POST['prio']."',
						'".$_POST['hours']."',
						'".$_POST['severity']."',
						NOW())";
					dbq($sql);
		#			echo "<br />";
			}
		}
		header("Location: index.php?zoom_id=".$_GET['zoom_id']."");
		exit();
	}
}

require_once("top.php");

if(empty($_GET['pid']))
{
	$pid = 0;
}
else
{
	$pid = $_GET['pid'];
}

echo "<form action='addtask.php?zoom_id=".$_GET['zoom_id']."' method='POST'>";

echo "txt";
echo "<textarea name=txt>";
echo "</textarea>";
echo "<br />\n";

echo "<input type='hidden' name='pid' value='".$pid."' />";
#echo "txt<input type='text' name='txt' /><br/>\n";
echo "hours<input type='text' value='1' name='hours' /><br/>\n";

echo "prio<select name='prio'>\n";
for($i=0; $i<=10; $i++)
{
	echo "<option ".(($i==5) ? "selected='selected'" : "")." value='".$i."'>".$i."</option>\n";
}
echo "</select><br/>\n";

echo "severity<select name='severity'>\n";
for($i=0; $i<=10; $i++)
{
	echo "<option ".(($i==5) ? "selected='selected'" : "")." value='".$i."'>".$i."</option>\n";
}
echo "</select><br/>\n";

echo "<input type='submit' name='submit' value='submit' />";
echo "</form>";

require_once("bottom.php");
?>